package com.one.blocks.rbac.controller.convert.worker;

import com.one.blocks.mvc.controller.convert.BaseConvert;
import com.one.blocks.rbac.domain.BaseDomain;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

import static com.one.blocks.mvc.constant.MvcConstant.CONVERT_CREATE_BY;
import static com.one.blocks.mvc.constant.MvcConstant.CONVERT_CREATE_TIME;
import static com.one.blocks.mvc.constant.MvcConstant.CONVERT_ID;
import static com.one.blocks.mvc.constant.MvcConstant.CONVERT_UPDATE_BY;
import static com.one.blocks.mvc.constant.MvcConstant.CONVERT_UPDATE_TIME;

/**
 * @author linfuxin Created on 2022-02-14 11:21:00
 */
public interface BaseDomainConvert<T extends BaseDomain, V, Q> extends BaseConvert<T, V, Q> {

    /**
     * 添加参数转换
     *
     * @param v 前端参数对象
     * @return 数据对象
     */
    @Named("voToEntityIgnoreId")
    @Mapping(target = CONVERT_ID, ignore = true)
    @Mapping(target = CONVERT_CREATE_BY, expression = "java(SubjectHelper.getSubjectId())")
    @Mapping(target = CONVERT_CREATE_TIME, expression = "java(SubjectHelper.getAccessTime())")
    @Mapping(target = CONVERT_UPDATE_BY, ignore = true)
    @Mapping(target = CONVERT_UPDATE_TIME, ignore = true)
    @Override
    T voToEntityIgnoreId(V v);

    /**
     * 更新参数转换
     *
     * @param v 前端参数
     * @return 业务封装对象
     */
    @Named("voToEntity")
    @Mapping(target = CONVERT_CREATE_BY, ignore = true)
    @Mapping(target = CONVERT_CREATE_TIME, ignore = true)
    @Mapping(target = CONVERT_UPDATE_BY, expression = "java(SubjectHelper.getSubjectId())")
    @Mapping(target = CONVERT_UPDATE_TIME, expression = "java(SubjectHelper.getAccessTime())")
    @Override
    T voToEntity(V v);
}